home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-23 | 8.0 KB | 328 lines | [TEXT/PJMM] |
- { Initialize.p functions related to starting up the program }
- unit Init;
- interface
-
- function Initialize: Boolean;
- procedure InitTime;
- implementation
- uses
- Preferences, MySpeech, Watch, Utility, AppleEvents, MyAppleEvent, PPCToolBox, GestaltEqu;
- const
- WATCH_PICT_ID = BASE_RES_ID + 1;
- BW_WATCH_PICT_ID = BASE_RES_ID + 2;
- DAY_RECT_PICT_ID = BASE_RES_ID + 3;
- ABOUT_ITEM = 1;
- APPLE_MENU_ID = BASE_RES_ID;
- FILE_MENU_ID = BASE_RES_ID + 1;
- EDIT_MENU_ID = BASE_RES_ID + 2;
- CLOCK_MENU_ID = BASE_RES_ID + 3;
- DAYS_LEFT_SPEECH = 1;
-
- (* InitTime, procedure to figure out the seconds value of the last second*)
- (*of the Clinton administration*)
-
- procedure InitTime;
- var
- dateRec: DateTimeRec;
- time, endTime: LONGINT;
- nextYear: integer;
- begin
- GetDateTime(time);
- time := time - GetGMTDelta;
- Secs2Date(time, dateRec);
- nextYear := dateRec.year;
- with dateRec do
- begin
- month := 1;
- day := 20;
- hour := 17; {* this is Greenwich mean time *}
- minute := 0;
- second := 0;
- dayOfWeek := 1;
- end;
- case (nextYear mod 4) of
- 0:
- nextYear := dateRec.year + 1;
- 1:
- begin
- dateRec.year := nextYear;
- Date2Secs(dateRec, endTime);
- if time > endTime then
- begin
- nextYear := nextYear + 4;
- end;
-
- end;
- 2:
- nextYear := dateRec.year + 3;
- 3:
- nextYear := dateRec.year + 2;
- end;
- dateRec.year := nextYear;
- Date2Secs(dateRec, gEndTime);
- gEndTime := gEndTime + GetGMTDelta;
- end;
-
- (* InitMyWindow, just load in my window and return TRUE if everything*)
- (*is ok *)
- function InitMyWindow: Boolean;
- var
- startPoint, topPoint, endPoint: Point;
- theGrayRgn: RgnHandle;
- begin
- if gColorAvailable then
- begin
- gWindow := GetNewCWindow(BASE_RES_ID, nil, WindowPtr(-1));
- end
- else
- begin
- gWindow := GetNewWindow(BASE_RES_ID, nil, WindowPtr(-1));
- end;
- if gWindow = nil then
- begin
- InitMyWindow := FALSE;
- end
- else
- begin
- SetPort(gWindow);
- startPoint := gPreferences.location;
- if (startPoint.h = 0) and (startPoint.v = 0) then
- begin
- LocalToGlobal(startPoint);
- end
- else
- begin
- startPoint := gPreferences.location;
- end;
- { is the saved window position valid ? }
- theGrayRgn := GetGrayRgn;
- endPoint := startPoint;
- endPoint.h := endPoint.h + 25;
- endPoint.v := endPoint.v + 25;
- topPoint := startPoint;
- topPoint.v := topPoint.v - 10;
- if (PtInRgn(endPoint, theGrayRgn)) and (PtInRgn(topPoint, theGrayRgn)) then
- begin
- MoveWindow(gWindow, startPoint.h, startPoint.v, TRUE);
- end;
- if gPreferences.zoomed = FALSE then
- begin
- gZoomed := TRUE;
- end
- else
- gZoomed := FALSE;
- { the flag control is used to control zooming }
- gZoomCtl := GetNewControl(BASE_RES_ID, gWindow);
- InitMyWindow := TRUE;
- end;
- end;
-
- { we store the time strings as handles with starting points }
- { we also load the pictures in here too }
- function InitMyStrings: Boolean;
- var
- fontHeight, i, cellHeight, width: integer;
- fInfo: FontInfo;
- currPoint: Point;
- tempString: StringHandle;
- ok: Boolean;
- pictRect, erRect: Rect;
- aString: Str255;
- begin
- ok := TRUE;
- GetFontInfo(fInfo);
- fontHeight := fInfo.ascent + fInfo.descent;
-
- gFramePict := GetPicture(BASE_RES_ID);
- gDayRectPict := GetPicture(DAY_RECT_PICT_ID);
- if gColorAvailable then
- begin
- gWatchPict := GetPicture(WATCH_PICT_ID);
- end
- else
- begin
- gWatchPict := GetPicture(BW_WATCH_PICT_ID);
- end;
-
- if (gFramePict <> nil) and (gWatchPict <> nil) and (gDayRectPict <> nil) then
- begin
- pictRect := gFramePict^^.picFrame;
- width := pictRect.right - pictRect.left;
- cellHeight := pictRect.bottom - pictRect.top;
- gFramePict^^.picFrame := pictRect;
- cellHeight := (pictRect.bottom - pictRect.top) div NUM_FIELDS;
- aString := '888';
- width := StringWidth(aString);
- currPoint.h := pictRect.right - width - 5;
- currPoint.v := pictRect.top + fInfo.ascent + 3;
- erRect.left := currPoint.h;
- erRect.right := currPoint.h + width - 1;
- pictRect := gWatchPict^^.picFrame;
- width := (pictRect.right - pictRect.left) div 2;
- gLongHandLen := width - 7;
- gShortHandLen := width div 2 - 2;
- gLongHandLenSquared := gLongHandLen;
- gLongHandLenSquared := gLongHandLenSquared * gLongHandLenSquared;
- gShortHandLenSquared := gShortHandLen;
- gShortHandLenSquared := gShortHandLenSquared * gShortHandLenSquared;
- CalcCenter(FALSE);
-
- end
- else
- begin
- ok := FALSE;
- end;
- i := 1;
- while (i <= NUM_FIELDS) and (ok = TRUE) do
- begin
- tempString := StringHandle(NewHandleClear(12));
- with gRectArray[i] do
- begin
- startPnt := currPoint;
- erRect.top := currPoint.v - fInfo.ascent;
- erRect.bottom := currPoint.v + fInfo.descent;
- blankRect := erRect;
- theString := tempString;
- lastValue := 99;
- end;
- currPoint.v := currPoint.v + cellHeight;
- if tempString = nil then
- begin
- ok := FALSE;
- end;
- i := i + 1;
- end;
- InitMyStrings := ok;
- end;
-
- (* Initialize, function that loads up the window and inits all the*)
- (*pertinent global variables.*)
- function InitMyMenu: Boolean;
- var
- myMenuBar: Handle;
- aMenu: MenuHandle;
- begin
- InitMyMenu := TRUE;
- myMenuBar := GetNewMBar(BASE_RES_ID);
- if myMenuBar <> nil then
- begin
- SetMenuBar(myMenuBar);
- DisposHandle(myMenuBar);
- aMenu := GetMenu(CLOCK_MENU_ID);
- if gSpeechAvailable = FALSE then
- begin
- DisableItem(aMenu, 0);
- end;
-
- aMenu := GetMHandle(APPLE_MENU_ID);
- AddResMenu(aMenu, 'DRVR');
- DrawMenuBar;
- end
- else
- begin
- InitMyMenu := FALSE;
- end;
-
- end;
- { we use the PPC toolbox to communicate with the daemon }
- function InitMyPPC: Boolean;
- var
- PPCAttributes: LONGINT;
- err: OSErr;
- begin
- err := Gestalt(gestaltPPCToolboxAttr, PPCAttributes);
- if (err = noErr) then
- begin
- if BitTst(@PPCAttributes, 31 - gestaltPPCSupportsRealTime) then
- begin
- err := PPCInit;
- end;
- end;
- if err = noErr then
- begin
- InitMyPPC := TRUE;
- end
- else
- begin
- InitMyPPC := FALSE;
- end;
- end;
- function InitEnvirons: Boolean;
- var
- theSysEnv: SysEnvRec;
- iErr: OSErr;
- dummy: integer;
- version: integer;
- globRect: Rect;
- gdh: GDHandle;
- theDevPixMap: PixMapHandle;
- response: LONGINT;
- begin
- gRadDegRatio := 0.0174532952;
- gDone := FALSE;
- gZoomed := TRUE;
- iErr := SysEnvirons(1, theSysEnv);
- version := BitShift(theSysEnv.systemVersion, -8);
- if (iErr = 0) and (version >= 7) and (InitMyPPC) then
- begin
- InitEnvirons := TRUE;
- gFPUAvailable := theSysEnv.hasFPU;
- gColorAvailable := theSysEnv.hasColorQD;
- gSpeechAvailable := IsSpeechAvailable;
-
- end
- else
- begin
- { we can't run in this environment }
- dummy := StopAlert(401, nil);
- InitEnvirons := FALSE;
- end;
- end;
-
- procedure InitPrefs;
- begin
- DoPrefDefault(gPreferences);
- GetPreferences(gPreferences);
- end;
- procedure InstallAppEvents;
- var
- myErr: OSErr;
- begin
- myErr := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleODOC, 0, FALSE);
- myErr := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @HandleQuit, 0, FALSE);
- myErr := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, @HandlePDOC, 0, FALSE);
- myErr := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @HandleOApp, 0, FALSE);
- end;
- function Initialize: Boolean;
- var
- dummy: Boolean;
- days: LONGINT;
- begin
- InitTime;
- InitPrefs;
- if (InitEnvirons = FALSE) or (InitMyWindow = FALSE) or (InitMyStrings = FALSE) or (InitMyMenu = FALSE) then
- begin
- Initialize := FALSE;
- end
- else
- begin
- ValidatePrefs(gPreferences);
- GetDateTime(days);
- randSeed := days;
- if gPreferences.sayDays then
- begin
-
- days := abs(days - gEndTime);
- days := days + 12 * 60 * 60;
- days := days div (86400);
- if gSpeechAvailable then
- SayNumbers(days, DAYS_LEFT_SPEECH);
- end;
- InstallAppEvents;
- dummy := FindDepth;
- dummy := InitMyGWorlds; (* if this fails, I'll just draw the face manually *)
- gChimed := FALSE;
- Initialize := TRUE;
- end;
- end;
- end.